<%@ page contentType="text/html; charset=utf-8" %>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html charset=gb2312">

    <title>Document</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css"
          integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.params.js"></script>
    <style>
        body{
            text-align: center;
            margin: 10px;
        }
        .box{
            border-radius: 20%;
        }
        td{
            border: 1px solid pink;
            text-align: center;
        }

    </style>
</head>

<body>
<h1>客户资料表</h1>
<table class="table table-condensed">
    <tr >
        <button onclick="addTel()">添加回访记录</button>
        公司名称:<input type="text" id="compName">
        法师姓名:<input type="text" id="ownerName">
        <button onclick="selectByName()">查询</button>
    </tr>
    <tr>
        <td>选择</td>
        <td>公司名称</td>
        <td>法师名称</td>
        <td>联系电话</td>
        <td>公司简介</td>
        <td>操作</td>
    </tr>
    <tbody id="tbody">

    </tbody>

</table>
<table class="table table-condensed">
    <tr>
        <td>回访人姓名</td>
        <td>回访时间</td>
        <td>回访分类</td>
        <td>回访结果</td>
        <td>回访方式</td>
    </tr>
    <tbody id="tal">

    </tbody>

</table>

<script>
    $(function(){
        getAll();
    })
    function  getAll(){
        //异步获取出行方式
        $.getJSON("/getAll.do",function(res){
            $("#tbody").html("");
            for(var i in res){
                $("#tbody").append('<tr><td><input type="radio" class="box" name="id" id="'+res[i].cid+'" value="'+res[i].cid+'"></td><td>'+res[i].compName+'</td><td>'+res[i].ownerName+'</td><td>'+res[i].ownerTel+'</td><td>'+res[i].compInfo+'</td><td><button onclick="delete1('+res[i].cid+')">删除</button><button onclick="selectVal('+res[i].cid+')">查看所有回访</button></td></tr>');
            }
            console.log(res)
        })
    }

    function delete1(cid){
        $.getJSON("/deleteComp.do?cid="+cid,function(res){
            getAll();
            console.log(res)
        })
    }
    function selectVal(cid){
        $.getJSON("/Tel/getOneCompTel.do?cid="+cid,function(res){
            $("#tal").html("");
            for(var i in res){
                $("#tal").append('<tr><td>'+res[i].telName+'</td><td>'+res[i].telTime+'</td><td>'+res[i].visitReason+'</td><td>'+res[i].visitReturn+'</td><td>'+res[i].visitType+'</td></tr>');
            }
        })
    }
    function addTel(){
        let cid =$("input[name='id']:checked").val();
        window.location.href = "add.jsp?cid="+cid
    }
    function selectByName(){
        let compName = $("#compName").val().trim();
        let ownerName = $("#ownerName").val().trim();
        let url = "";
        console.log(":"+compName,":"+ownerName)
         if (compName != null && compName != "" && ownerName != null && ownerName != ""){
              url = "/selectByName.do?ownerName="+ownerName+"&compName="+compName;
         }else if (compName == null || compName == ""){
                url = "/selectByName.do?ownerName="+ownerName
            }else if (ownerName == null || ownerName == ""){
                url = "/selectByName.do?compName="+compName
            }
            console.log(url)
            $.getJSON(url,function(res){
                console.log(res)
                $("#tbody").html("");

                for(var i in res){
                    $("#tbody").append('<tr><td><input type="radio" class="box" name="id"></td><td>'+res[i].compName+'</td><td>'+res[i].ownerName+'</td><td>'+res[i].ownerTel+'</td><td>'+res[i].compInfo+'</td><td><button onclick="delete1('+res[i].cid+')">删除</button><button onclick="selectVal('+res[i].cid+')">查看所有回访</button></td></tr>');
                }
                if (res == null || res.length == 0){
                    console.log("111")
                    getAll();

                }
            })
    }
</script>
</body>
</html>
